//package com.zj.java21demo.utils;
//
//import org.springframework.stereotype.Component;
//
//import javax.crypto.SecretKeyFactory;
//import javax.crypto.spec.PBEKeySpec;
//import java.security.NoSuchAlgorithmException;
//import java.security.spec.InvalidKeySpecException;
//import java.util.Arrays;
//import java.util.Base64;
//
///**
// * @Author: sunzhaoyu
// * @Date: 2023/5/26$
// */
//@Component
//public class PasswordUtils {
//
//
//    public static final byte[] FIXED_SALT = { 0x01, 0x23, 0x45, 0x67, 0x23, 0x59, 0x17, 0x69 };
//
//    public static String encryptPassword(String password) {
//        String encryptedPassword = null;
//
//        try {
//            int iterations = 10000;
//            int keyLength = 256;
//            char[] passwordChars = password.toCharArray();
//
//            PBEKeySpec spec = new PBEKeySpec(passwordChars, FIXED_SALT, iterations, keyLength);
//            SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
//            byte[] hashedBytes = skf.generateSecret(spec).getEncoded();
//
//            encryptedPassword = Base64.getEncoder().encodeToString(hashedBytes);
//        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
//            e.printStackTrace();
//        }
//
//        return encryptedPassword;
//    }
//
//    public static boolean verifyPassword(String password, String encryptedPassword) {
//        try {
//            byte[] hashedBytes = Base64.getDecoder().decode(encryptedPassword);
//
//            int iterations = 10000;
//            int keyLength = 256;
//
//            PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), FIXED_SALT, iterations, keyLength);
//            SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
//            byte[] hashedBytesToVerify = skf.generateSecret(spec).getEncoded();
//
//            return Arrays.equals(hashedBytes, hashedBytesToVerify);
//        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
//            e.printStackTrace();
//        }
//
//        return false;
//    }
//
//}